package com.mantou.proxyservice.proxeservice.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.mantou.proxyservice.collection.Collecter;
import com.mantou.proxyservice.scheduler.CollecterTask;
import com.mantou.proxyservice.utils.ProxyUtil;

@Controller
@RequestMapping("/system")
public class SystemInfoController {
	private final Logger logger = LoggerFactory.getLogger(SystemInfoController.class);
	

	@RequestMapping(value = "/static", method = RequestMethod.GET)
	@ResponseBody
	public String avaiable(){
		JSONArray jsonArray = new JSONArray();
		List<Collecter> collecters = CollecterTask.getCollecters(); 
		if(collecters == null){
			logger.info("server not start to collect proxy resource");
			return jsonArray.toJSONString();
		}
		for(Collecter collecter:collecters){
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("batchSize", collecter.getBatchsize());
			jsonObject.put("charset", collecter.getCharset());
			jsonObject.put("collectNumber", collecter.getGetnumber());
			jsonObject.put("hibtate", collecter.getHibrate());
			jsonObject.put("website", collecter.getWebsite());
			jsonObject.put("errorinfo", collecter.getErrorinfo());
			jsonArray.add(jsonObject);
		}
		return jsonArray.toJSONString();
	}
	@RequestMapping(value = "/key", method = RequestMethod.GET)
	@ResponseBody
	public String testkey(){
		return ProxyUtil.testkey;
	}
}
